import { createRouter, createWebHistory } from "vue-router";

// 导入组件
import FilmView from "../views/FilmView.vue";
import CinemaView from "../views/CinemaView.vue";
import NewsView from "../views/NewsView.vue";
import MineView from "../views/MineView.vue";
import AxiosDemo from "../../demos/AxiosDemo.vue";
import NowPlaying from "../components/film/NowPlaying.vue";
import ComingSoon from "../components/film/ComingSoon.vue";
import Detail from "../components/film/Detail.vue";
import NotFound from "../views/NotFound.vue";
import CitySelection from "../views/CitySelection.vue";

const router = createRouter({
   history: createWebHistory(import.meta.env.BASE_URL),
   //定义路由规则
   routes: [
      //刚进来访问的页面
      {
         path: "/film",
         redirect: "/film/nowPlaying",
      },
      //电影
      {
         path: "/film",
         name: "film",
         meta: { title: "电影", isTabPage: true },
         component: FilmView,
         //子页面
         children: [
            {
               path: "nowPlaying",
               component: NowPlaying,
            },
            {
               path: "comingSoon",
               component: ComingSoon,
            },
         ],
      },

      {
         path: "/film/:id(\\d{4})",
         name: "detail",
         meta: { hideNavBar: true, hideTabBar: true },
         component: Detail,
      },
      //影院
      {
         path: "/cinema",
         name: "cinema",
         meta: { title: "影院", isTabPage: true },
         component: CinemaView,
      },
      //资讯
      {
         path: "/news",
         name: "news",
         meta: { title: "资讯", isTabPage: true },
         component: NewsView,
      },

      //我的
      {
         path: "/mine",
         name: "mine",
         meta: { title: "我的", hideNavBar: true, isTabPage: true },
         component: MineView,
      },

      {
         path: "/demos/axios",
         name: "axios",
         component: AxiosDemo,
      },

      {
         path: "/cities",
         name: "cities",
         meta: { title: "当前城市-", hideTabBar: true },
         component: CitySelection,
      },

      // 匹配不上执行这个
      { path: "/:pm(.*)*", name: "NotFound", component: NotFound },
   ],
});

// 对外导出路由器
export default router;
